package edu.bu.cs673.superkids123.children.model;

import java.util.ArrayList;
import java.util.Collection;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

@Entity
@Table(name="Games")
public class Game {
	/**
	 * @author Abdelghani Bhalla
	 */
	@Id @GeneratedValue
	@Column(name="GameID")
	private int id;
	
	@Column(name="GameName")
	private String name;
	
	@Column(name="GameDescription")
	private String description;
	
	@Column(name="IsActive")
	private boolean isActive;
	
	@Column(name = "GameIcon")
	private String icon;
	
	public boolean isActive() {
		return isActive;
	}

	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}
	@ManyToOne
	@JoinColumn(name="GameLevelID")
	@NotFound(action=NotFoundAction.IGNORE)
	private Level level;
	
	@OneToMany(mappedBy="game")
	private Collection<Question> questions = new ArrayList<Question>();
	
	@OneToMany(mappedBy="game",fetch=FetchType.EAGER)
	@Cascade({CascadeType.ALL})
	private Collection<CompletedGame> CompletedGames = new ArrayList<CompletedGame>();
	
	public Collection<CompletedGame> getCompletedGames() {
		return CompletedGames;
	}

	public void setCompletedGames(Collection<CompletedGame> completedGames) {
		CompletedGames = completedGames;
	}

	public Collection<Question> getQuestions() {
		return questions;
	}

	public void setQuestions(Collection<Question> questions) {
		this.questions = questions;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public Level getLevel() {
		return level;
	}

	public void setLevel(Level level) {
		this.level = level;
	}

	
	public Game(String name)
	{
		super();
		this.name = name;
	}

	public String getName() {
		return name;
	}
	public Game(String name, String description, boolean isactive){
		this.name = name;
		this.description = description;
		this.isActive = isactive;
	}
	public Game()
	{
	}
	public void addCompletedGame(CompletedGame game)
	{
		game.setGame(this);
		CompletedGames.add(game);
	}
}
